﻿using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AgileLogistics.View.Cailiao
{
    /// <summary>
    /// BillPage.xaml 的交互逻辑
    /// </summary>
    public partial class BillPage : Page
    {
        ViewModel.MaterialViewModel vm;
        Model.DBContext dBContext = new Model.DBContext();

        public BillPage()
        {
            InitializeComponent();

            vm = DataContext as ViewModel.MaterialViewModel;


            vm.CurrBill = null;
            vm.BillList = dBContext.DB.Queryable<Model.MaterialBill>().Where(m=>m.State=="待审核").ToList();
            if(vm.BillList.Count<=0)
            {
                txt_NullText.Visibility = Visibility.Visible;
            }
        }

        private void btn_Check_Click(object sender, RoutedEventArgs e)
        {
            if(vm.CurrBill==null)
            {
                Growl.WarningGlobal("请选择申请单！");
                return;
            }

            vm.CurrBill.IsCheck = true;
            vm.CurrBill.State = "已通过";
            dBContext.DB.Updateable<Model.MaterialBill>(vm.CurrBill).ExecuteCommand();
            vm.BillList = dBContext.DB.Queryable<Model.MaterialBill>().Where(m => m.State == "待审核").ToList();

            Growl.SuccessGlobal("已通过！");
        }

        private void btn_BoHui_Click(object sender, RoutedEventArgs e)
        {
            if (vm.CurrBill == null)
            {
                Growl.WarningGlobal("请选择申请单！");
                return;
            }
            HandyControl.Controls.Dialog.Show<View.Cailiao.BoHuiUC>();
        }
    }
}
